import axios from "axios";

import {baseUrl, baseLogin} from './config.js';


axios.interceptors.response.use(response => {
    return response;
}, error => {
    if (error && error.response) {
        switch (error.response.status) {
            case 400:
                error.message = '请求错误';
                break;
            case 401:
                error.message = '未授权，请登录';
                break;
            case 403:
                error.message = '拒绝访问';
                break;
            case 404:
                error.message = `请求地址出错: ${error.response.config.url}`;
                break;
            case 408:
                error.message = '请求超时';
                break;
            case 500:
                error.message = '服务器内部错误';
                break;
            case 501:
                error.message = '服务未实现';
                break;
            case 502:
                error.message = '网关错误';
                break;
            case 503:
                error.message = '服务不可用';
                break;
            case 504:
                error.message = '网关超时';
                break;
            case 505:
                error.message = 'HTTP版本不受支持';
                break;
            default:
        }
    }
    return Promise.reject(error)
});

// 添加请求拦截器
axios.interceptors.request.use(config => {
	if (sessionStorage.getItem('user')) {
		config.headers.common['X-Authentication'] = JSON.parse(sessionStorage.getItem('user'));
	}
    return config;
}, error => {
    // 对请求错误做些什么
    return Promise.reject(error);
});


let instance = axios.create({
    baseURL: baseUrl,
    timeout: 100000
});

let base = '';
/*测试数据*/
export const getUserList = params => {
    return axios.get(`${base}/user/list`, {params: params});
};
export const getUserListPage = params => {
    return axios.get(`${base}/user/listpage`, {params: params});
};
export const removeUser = params => {
    return axios.get(`${base}/user/remove`, {params: params});
};
export const batchRemoveUser = params => {
    return axios.get(`${base}/user/batchremove`, {params: params});
};
export const editUser = params => {
    return axios.get(`${base}/user/edit`, {params: params});
};
export const addUser = params => {
    return axios.get(`${base}/user/add`, {params: params});
};
/*
* 登录
* */
export const requestLogin = params => {
    return axios.post(`${baseLogin}api/auth/login/admin`, params).then(res => res.data);
};
/*
* 上传
* */
export const uploadAuth = params => {
    return axios.post(`${baseLogin}/api/sys/vod/upload/auth`, params).then(res => res.data);
};
/*
* 系统设置
* */
export const settingList = params => {
    return axios.post(`${baseUrl}/setting/system/list`, params).then(res => res.data);
};
export const settingAdd = params => {
    return axios.post(`${baseUrl}/setting/system/add`, params).then(res => res.data);
};
export const settingUpdate = params => {
    return axios.post(`${baseUrl}/setting/system/update`, params).then(res => res.data);
};
export const settingFall = (id, params) => {
    return axios.post(`${baseUrl}/setting/system/info/` + id, params).then(res => res.data);
};

/*
* 用户设置
* */
export const userSettingInfo = params => {
    return axios.post(`${baseUrl}/setting/user/info`, params).then(res => res.data);
};
export const userSettingUpdate = params => {
    return axios.post(`${baseUrl}/setting/user/update`, params).then(res => res.data);
};
/*
* 规则管理
* */
export const ruleList = params => {
    return axios.post(`${baseUrl}/rules/list`, params).then(res => res.data);
};
export const ruleAdd = params => {
    return axios.post(`${baseUrl}/rules/add`, params).then(res => res.data);
};
export const ruleUpdate = params => {
    return axios.post(`${baseUrl}/rules/update`, params).then(res => res.data);
};
/*
* APP首页设置
* */
export const moduleSetting = params => {
    return axios.post(`${baseUrl}/setting/home/module/list`, params).then(res => res.data);
};
export const moduleUpdate = params => {
    return axios.post(`${baseUrl}/setting/home/module/update`, params).then(res => res.data);
};
export const moduleAdd = params => {
    return axios.post(`${baseUrl}/setting/home/module/add`, params).then(res => res.data);
};
export const moduleDelete = (id, params) => {
    return axios.post(`${baseUrl}/setting/home/module/delete/` + id, params).then(res => res.data);
};
/*幻灯片模块*/
export const slideList = params => {
    return axios.post(`${baseUrl}/setting/home/module/slide/list`, params).then(res => res.data);
};
export const slideUpdate = params => {
    return axios.post(`${baseUrl}/setting/home/module/slide/update`, params).then(res => res.data);
};
export const slideAdd = params => {
    return axios.post(`${baseUrl}/setting/home/module/slide/add`, params).then(res => res.data);
};
export const slideDelete = (id, params) => {
    return axios.post(`${baseUrl}/setting/home/module/slide/delete/` + id, params).then(res => res.data);
};
/*公告设置*/
export const noticeList = params => {
    return axios.post(`${baseUrl}/setting/home/module/notice/list`, params).then(res => res.data);
};
export const noticeUpdate = params => {
    return axios.post(`${baseUrl}/setting/home/module/notice/update`, params).then(res => res.data);
};
export const noticeAdd = params => {
    return axios.post(`${baseUrl}/setting/home/module/notice/add`, params).then(res => res.data);
};
export const noticeDelete = (id, params) => {
    return axios.post(`${baseUrl}/setting/home/module/notice/delete/` + id, params).then(res => res.data);
};
/*图标设置*/
export const iconList = params => {
    return axios.post(`${baseUrl}/setting/home/module/icon/list`, params).then(res => res.data);
};
export const iconUpdate = params => {
    return axios.post(`${baseUrl}/setting/home/module/icon/update`, params).then(res => res.data);
};
export const iconAdd = params => {
    return axios.post(`${baseUrl}/setting/home/module/icon/add`, params).then(res => res.data);
};
export const iconDelete = (id, params) => {
    return axios.post(`${baseUrl}/setting/home/module/icon/delete/` + id, params).then(res => res.data);
};
/*教育设置*/
export const educationList = params => {
    return axios.post(`${baseUrl}/setting/home/module/education/list`, params).then(res => res.data);
};
export const educationUpdate = params => {
    return axios.post(`${baseUrl}/setting/home/module/education/update`, params).then(res => res.data);
};
export const educationAdd = params => {
    return axios.post(`${baseUrl}/setting/home/module/education/add`, params).then(res => res.data);
};
export const educationDelete = (id, params) => {
    return axios.post(`${baseUrl}/setting/home/module/education/delete/` + id, params).then(res => res.data);
};
/*证券开户*/
export const securityList = params => {
    return axios.post(`${baseUrl}/setting/home/module/security/open/list`, params).then(res => res.data);
};
export const securityUpdate = params => {
    return axios.post(`${baseUrl}/setting/home/module/security/open/update`, params).then(res => res.data);
};
export const securityAdd = params => {
    return axios.post(`${baseUrl}/setting/home/module/security/open/add`, params).then(res => res.data);
};
export const securityDelete = (id, params) => {
    return axios.post(`${baseUrl}/setting/home/module/security/open/delete/` + id, params).then(res => res.data);
};
/*金融产品模块*/
export const productList = params => {
    return axios.post(`${baseUrl}/setting/home/module/product/list`, params).then(res => res.data);
};
export const productUpdate = params => {
    return axios.post(`${baseUrl}/setting/home/module/product/update`, params).then(res => res.data);
};
export const productAdd = params => {
    return axios.post(`${baseUrl}/setting/home/module/product/add`, params).then(res => res.data);
};
export const productDelete = (id, params) => {
    return axios.post(`${baseUrl}/setting/home/module/product/delete/` + id, params).then(res => res.data);
};
/*自定义*/
export const customerList = (id,params) => {
    return axios.post(`${baseUrl}/setting/home/module/customer/list/` + id, params).then(res => res.data);
};
export const customerUpdate = params => {
    return axios.post(`${baseUrl}/setting/home/module/customer/update/`, params).then(res => res.data);
};
export const customerAdd = (id,params) => {
    return axios.post(`${baseUrl}/setting/home/module/customer/add/` + id, params).then(res => res.data);
};
export const customerDelete = (id, params) => {
    return axios.post(`${baseUrl}/setting/home/module/customer/delete/` + id, params).then(res => res.data);
};

/*
* 分析管理
* */
export const analysisList = params => {
    return axios.post(`${baseUrl}/analysis/list`, params).then(res => res.data);
};
export const analysisDel = (id, params) => {
    return axios.post(`${baseUrl}/analysis/delete/` + id, params).then(res => res.data);
};
export const analysisNew = params => {
    return axios.post(`${baseUrl}/analysis/add`, params).then(res => res.data);
};
export const analysisEdit = params => {
    return axios.post(`${baseUrl}/analysis/update`, params).then(res => res.data);
};
/*
* 活动管理
* * */
export const activityList = params => {
    return axios.post(`${baseUrl}/activity/list`, params).then(res => res.data);
};
export const activityEdit = params => {
    return axios.post(`${baseUrl}/activity/update`, params).then(res => res.data);
};
export const activityNew = params => {
    return axios.post(`${baseUrl}/activity/add`, params).then(res => res.data);
};
export const activityDel = (id, params) => {
    return axios.post(`${baseUrl}/activity/delete/` + id, params).then(res => res.data);
};
/*
* 消息管理
* * */
export const advicesList = params => {
    return axios.post(`${baseUrl}/message/list`, params).then(res => res.data);
};
export const advicesNew = params => {
    return axios.post(`${baseUrl}/message/add`, params).then(res => res.data);
};
export const advicesEdit = params => {
    return axios.post(`${baseUrl}/message/update`, params).then(res => res.data);
};
export const advicesDel = (id, params) => {
    return axios.post(`${baseUrl}/message/delete/` + id, params).then(res => res.data);
};
export const advicesSings = (id, params) => {
    return axios.post(`${baseUrl}/message/info/` + id, params).then(res => res.data);
};

/*
* 意见反馈管理
* */
export const feedbackList = params => {
    return axios.post(`${baseUrl}/feedback/list`, params).then(res => res.data);
};
export const feedbackDel = (id, params) => {
    return axios.post(`${baseUrl}/feedback/delete/` + id, params).then(res => res.data);
};
/*
* 文章管理
* */
export const essayList = params => {
    return axios.post(`${baseUrl}/article/list`, params).then(res => res.data);
};
export const essayAdd = params => {
    return axios.post(`${baseUrl}/article/add`, params).then(res => res.data);
};
export const essayUpdate = params => {
    return axios.post(`${baseUrl}/article/update`, params).then(res => res.data);
};
export const essayListS = (id, params) => {
    return axios.post(`${baseUrl}/article/info/` + id, params).then(res => res.data);
};
export const essayDel = (id, params) => {
    return axios.post(`${baseUrl}/article/delete/` + id, params).then(res => res.data);
};

/*
* 说说
* */
export const talkList = params => {
    return axios.post(`${baseUrl}/circle/list`, params).then(res => res.data);
};
export const talkAdd = params => {
    return axios.post(`${baseUrl}/circle/add`, params).then(res => res.data);
};
export const talkUpdate = params => {
    return axios.post(`${baseUrl}/circle/update`, params).then(res => res.data);
};
export const talkDel = (id, params) => {
    return axios.post(`${baseUrl}/circle/delete/` + id, params).then(res => res.data);
};
export const talkListOne = (id, params) => {
    return axios.post(`${baseUrl}/circle/info/` + id, params).then(res => res.data);
};
export const talkComment = params => {
    return axios.post(`${baseUrl}/circle/comment`, params).then(res => res.data);
};
export const talkCommentDel = (id, params) => {
    return axios.post(`${baseUrl}/circle/comment/delete/` + id, params).then(res => res.data);
};
export const talkUp = (id, params) => {
    return axios.post(`${baseUrl}/circle/up/` + id, params).then(res => res.data);
};
/*
* 课程管理
* */
export const courseList = params => {
    return axios.post(`${baseUrl}/course/list`, params).then(res => res.data);
};
export const courseBuyList = params => {
    return axios.post(`${baseUrl}/course/buy/list`, params).then(res => res.data);
};
export const courseAdd = params => {
    return axios.post(`${baseUrl}/course/add`, params).then(res => res.data);
};
export const courseUpdate = params => {
    return axios.post(`${baseUrl}/course/update`, params).then(res => res.data);
};
export const courseDel = (id, params) => {
    return axios.post(`${baseUrl}/course/delete/` + id, params).then(res => res.data);
};
export const courseInfo = (id, params) => {
    return axios.post(`${baseUrl}/course/info/` + id, params).then(res => res.data);
};
export const courseRate = params => {
    return axios.post(`${baseUrl}/course/rate`, params).then(res => res.data);
};
export const courseBuy = params => {
    return axios.post(`${baseUrl}/course/buy`, params).then(res => res.data);
};
export const courseAudit = params => {
    return axios.post(`${baseUrl}/course/audit`, params).then(res => res.data);
};
export const courseOnAndOff = params => {
    return axios.post(`${baseUrl}/course/OnAndOff`, params).then(res => res.data);
};
/*
* 课节管理
* */
export const sectionList = params => {
    return axios.post(`${baseUrl}/section/list`, params).then(res => res.data);
};
export const sectionAdd = params => {
    return axios.post(`${baseUrl}/section/add`, params).then(res => res.data);
};
export const sectionUpdate = params => {
    return axios.post(`${baseUrl}/section/update`, params).then(res => res.data);
};
export const sectionDel = (id, params) => {
    return axios.post(`${baseUrl}/section/delete/` + id, params).then(res => res.data);
};
export const sectionInfo = (id, params) => {
    return axios.post(`${baseUrl}/section/info/` + id, params).then(res => res.data);
};
export const sectionCommentDel = (id, params) => {
    return axios.post(`${baseUrl}/section/comment/delete/` + id, params).then(res => res.data);
};
export const sectionComment = params => {
    return axios.post(`${baseUrl}/section/comment`, params).then(res => res.data);
};
export const sectionAuthor = params => {
    return axios.post(`${baseUrl}/section/author/comment`, params).then(res => res.data);
};
export const sectionCommentAudit = params => {
    return axios.post(`${baseUrl}/section/comment/audit`, params).then(res => res.data);
};




/*
角色管理
 */
export const roleList = params => {
    return axios.post(`${baseLogin}/api/sys/duties/list`, params).then(res => res.data);
};
export const roleSave = params => {
    return axios.post(`${baseLogin}/api/sys/duties/save`, params).then(res => res.data);
};

/*
用户管理
 */
export const userList = params => {
    return axios.post(`${baseLogin}/api/sys/user/list`, params).then(res => res.data);
};
export const userSave = params => {
    return axios.post(`${baseLogin}/api/sys/user/save`, params).then(res => res.data);
};
export const userDel = (id, params) => {
    return axios.post(`${baseLogin}/api/sys/user/delete/` + id, params).then(res => res.data);
};

/*
菜单管理
 */
export const menuTree = params => {
    return axios.get(`${baseLogin}/api/sys/menu/treeData`, params).then(res => res.data);
};
export const menuSave = params => {
    return axios.post(`${baseLogin}/api/sys/menu/save`, params).then(res => res.data);
};
export const menuDel = (id, params) => {
    return axios.post(`${baseLogin}/api/sys/menu/delete/` + id, params).then(res => res.data);
};

/*采集管理*/
export const gatherList = params => {
    return axios.post(`${baseUrl}/collection/list`, params).then(res => res.data);
};
export const gatherAdd = params => {
    return axios.post(`${baseUrl}/collection/add`, params).then(res => res.data);
};
export const gatherUpdate = params => {
    return axios.post(`${baseUrl}/collection/update`, params).then(res => res.data);
};
export const gatherStorage = params => {
    return axios.post(`${baseUrl}/collection/storage`, params).then(res => res.data);
};

/*
营销管理
 */
export const marketCourseList = params => {
    return axios.post(`${baseUrl}/marketCourse/list`, params).then(res => res.data);
};
export const marketCourseAdd = params => {
    return axios.post(`${baseUrl}/marketCourse/add`, params).then(res => res.data);
};
export const marketCourseDelete = (id, params) => {
    return axios.post(`${baseUrl}/marketCourse/delete/` + id, params).then(res => res.data);
};
/*
* 分类管理
* */
export const marketClassifyList = params => {
    return axios.post(`${baseUrl}/courseClassify/list`, params).then(res => res.data);
};
export const marketClassifyAdd = params => {
    return axios.post(`${baseUrl}/courseClassify/add`, params).then(res => res.data);
};
export const marketClassifyUpdate = params => {
    return axios.post(`${baseUrl}/courseClassify/update`, params).then(res => res.data);
};
export const marketClassifyListId = (id, params) => {
    return axios.post(`${baseLogin}/api/app/courseClassify/info/` + id, params).then(res => res.data);
};
export const marketClassifyDelete = (id, params) => {
    return axios.post(`${baseUrl}/courseClassify/delete/` + id, params).then(res => res.data);
};
/*
* 证券开户
* */
export const securityOpenList = params => {
    return axios.post(`${baseUrl}/securityOpen/list`, params).then(res => res.data);
};
export const securityOpenAdd = params => {
    return axios.post(`${baseUrl}/securityOpen/add`, params).then(res => res.data);
};
export const securityOpenUpdate = params => {
    return axios.post(`${baseUrl}/securityOpen/update`, params).then(res => res.data);
};
export const securityOpenDlete = (id, params) => {
    return axios.post(`${baseUrl}/securityOpen/delete/` + id, params).then(res => res.data);
};
export const securityOpenListId = (id, params) => {
    return axios.post(`${baseUrl}/securityOpen/info/` + id, params).then(res => res.data);
};
/*
* 阶段课程管理
* */
export const phaseList = params => {
    return axios.post(`${baseUrl}/stageCourse/list`, params).then(res => res.data);
};
export const phaseAdd = params => {
    return axios.post(`${baseUrl}/stageCourse/add`, params).then(res => res.data);
};
export const phaseUpdate = params => {
    return axios.post(`${baseUrl}/stageCourse/update`, params).then(res => res.data);
};
export const phaseDlete = (id, params) => {
    return axios.post(`${baseUrl}/stageCourse/delete/` + id, params).then(res => res.data);
};
export const phaseListId = (id, params) => {
    return axios.post(`${baseUrl}/stageCourse/info/` + id, params).then(res => res.data);
};
/*
* 广告管理
* */
export const advertList = params => {
    return axios.post(`${baseUrl}/poster/list`, params).then(res => res.data);
};
export const advertAdd = params => {
    return axios.post(`${baseUrl}/poster/add`, params).then(res => res.data);
};
export const advertUpdate = params => {
    return axios.post(`${baseUrl}/poster/update`, params).then(res => res.data);
};
export const advertDlete = (id, params) => {
    return axios.post(`${baseUrl}/poster/delete/` + id, params).then(res => res.data);
};
export const advertListId = (id, params) => {
    return axios.post(`${baseUrl}/poster/info/` + id, params).then(res => res.data);
};

